﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Xml.Linq;
using System.Diagnostics;

namespace JsonTest1.Module
{
    public class StudentModel
    {


        public string HeadUrl { get; set; }

        public string Name { get; set; }

        public int Age { get; set; }


    }


    public class ParserXml
    {
        public static ObservableCollection<StudentModel> parser(string xmlStr)
        {
            ObservableCollection<StudentModel> studentCollection = new ObservableCollection<StudentModel>();
            if (xmlStr != null)
            {
                try
                {
                    XDocument document = new XDocument();
                   document= XDocument.Parse(xmlStr);
                    foreach (XElement element in document.Element("Student").Descendants("user"))
                    {
                        studentCollection.Add(new StudentModel()
                        {
                            HeadUrl = element.Element("headurl").Value,
                            Name = element.Element("name").Value,
                            Age = Int32.Parse(element.Element("age").Value)
                        });
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.ToString());
                }

            }

            Debug.WriteLine(studentCollection.Count);

            return null;
        }

    }
}
